<?php
    $auth = Auth::getAuth('current_user');
    $db = new Database();
    $fs = new Functions();
    $Campaign_Functions = new Campaign_Functions();
?>
<div class="content">
    <!--- Bread Crumbs Menu -->
    <div class="breadLine">
        <ul class="breadcrumb">
            <li><a href="/">Admin</a> <span class="divider">></span></li>
            <li class="active"><a href="/">User</a> <span class="divider">></span></li>     
            <li class="active"><?php echo Config::get_page(); ?></li>
        </ul>
        <?php
            //echo $this->setLayout("breadcrumbs_right_menu");
        ?>
    </div>

   <div class="workplace">

        <div class="row-fluid">
            <div class="span12">
                <div class="head clearfix">
                    <div class="isw-calendar"></div>
                        <h1><?php echo Config::get_page(); ?></h1>
                    </div>
                    
                    <div class="row-fluid">
                        <div class="span5">
                            <div class="widget">
                                <div class="head dark">
                                    <div class="icon title_icon"><i class="fa fa-plus"></i></div>
                                    <h2>Create New Campaign</h2>
                                </div>                        
                                <div class="block-fluid">
                                    <form id="new_campaign" method="POST" action="/ajax/energy-chart-actions?action=add_campaign&type=add">
                                        <div class="row-form">
                                            <div class="span3">Titile:*</div>
                                            <div class="span9"><input type="text" name="campaign_title" class="validate[required]" placeholder="Enter your first name"></div>
                                        </div>
                                        <div class="row-form">
                                            <div class="span3">Brand Story:*</div>
                                            <div class="span9">
                                                <?php
                                                    
                                                    echo $Campaign_Functions->brand_story("brand_story","","validate[required]","","");
                                                ?>
                                                <input type="hidden" name="campaign_status" class="">
                                            </div>
                                        </div>
                                        <div class="row-form">
                                            <div class="span3">Campaign:*</div>
                                            <div class="span9">
                                                <?php
                                                    
                                                    echo $Campaign_Functions->select_campaign("campaign_id","","validate[required]","","");
                                                ?>
                                            </div>
                                        </div>
                                        <div class="row-form">
                                            <div class="span3">Description:*</div>
                                            <div class="span9"><textarea name="campaign_description" class="validate[required]" placeholder="Placeholder example"></textarea></div>
                                        </div>
                                        <div class="row-form" id="sad_draft">
                                            <div class="span3">Save as Draft:</div>
                                            <input type="checkbox" name="save_as_draft"  value="3"/>
                                        </div>
                                        <div class="toolbar bottom TAR">
                                            <button class="btn btn-info" type="button" onclick="$('#new_campaign').validationEngine('hide');">Hide prompts</button>
                                            <button class="btn btn-primary" id="submit">Submit</button>
                                            <!--<button class="btn btn-primary" id="sad">Save as Draft</button>-->
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <div class="span7">
                            <div class="widget">
                                <div class="head dark">
                                    <div class="icon title_icon"><i class="fa fa-list"></i></div>
                                    <h2>List of my Campaign</h2>  
                                </div>                        
                                <div class="block-fluid">

                                    <table class="tb_brochure" cellpadding="0" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <th><input type="checkbox" class="checkall"/></th>
                                                <th width="25%">Campaign By</th>
                                                <th width="20%">Title</th>
                                                <th width="20%">Campaign</th>
                                                <th width="20%">Description</th>
                                                <th width="20%">Status</th>
                                                <th width="15%" class="TAC">Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                                
                                                $tb_campaign = $db->tbl_name(TB_CAMPAIGN);
                                                $tb_users = $db->tbl_name(TB_USERS);
                                                $tb_accounts = $db->tbl_name(TB_ACCOUNTS);
                                                $tb_brand_category = $db->tbl_name(TB_BRAND_CATEGORY);
                                                $tb_campaign_status = $db->tbl_name(TB_CAMPAIGN_STATUS);
                                                $query = $db->query("
                                                    SELECT *,c.id as camID,cs.name as csName,cs.id as csID FROM $tb_campaign c 
                                                    LEFT JOIN $tb_users u ON c.user_id=u.id
                                                    LEFT JOIN $tb_accounts a ON u.account_id=a.id
                                                    LEFT JOIN $tb_campaign_status cs ON c.campaign_status_id=cs.id
                                                    WHERE c.user_id = {$db->escape($auth['id'])}
                                                    ","array");
                                                
                                                foreach($query as $data){
                                                    $encrypted_camp_id = $fs->base_encode_decode("encrypt", $data['camID']);
                                                    
                                                    $arr = array("campaign_title"        =>  $data['title'],
                                                                "campaign_id"      =>  $data['campaign_list_id'],
                                                                "campaign_description"   =>  $data['description'],
                                                                "save_as_draft"         =>  $data['csID'],
                                                                "brand_story"           =>  $data['brand_story'],
                                                                "campaign_status"       =>  $data['campaign_status_id']);
                                            ?>
                                            <tr id="camp_<?php echo $encrypted_camp_id; ?>" data-json="<?php echo htmlentities(json_encode($arr)); ?>">
                                                <td><input type="checkbox" name="[]" value=""/></td>
                                                <td><a href="#"><?php echo $data['first_name'] . " " . $data['last_name']; ?></a></td>
                                                <td><?php echo $data['title']; ?></td>
                                                <td><?php echo $Campaign_Functions->reload_selected_campaign($data['campaign_list_id']); ?></td>
                                                <td><?php echo $fs->truncateStringWords($data['description'], "20"); ?></td>
                                                <td><span class="label label-important"><?php echo $data['csName']; ?></span></td>
                                                <td class="TAC" data-id="<?php echo $encrypted_camp_id; ?>"  data-draft="<?php echo $data['csID']; ?>">
                                                    <?php if($data['campaign_status_id'] != "2"){ ?>
                                                    <a class="trigger_campaign tip cursor" data-type="edit" data-original-title="Edit this campaign."><span class="icon-pencil"></span></a> 
                                                    <?php } ?>
                                                    <a class="trigger_campaign tip cursor" data-type="remove" data-original-title="Remove this campaign"><span class="icon-trash"></span></a>
                                                </td>
                                            </tr>
                                            <?php } ?>
                                        </tbody>
                                    </table>
                                    <div style="float:left;padding: 5px;width:100%;" class="text-left">
                                        <button class="btn btn-small" type="button">Submit</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>    
        </div>

   </div>

</div> 